package main

import (
	"context"
	"fmt"
	"github.com/micro/go-micro"
	"github.com/micro/go-micro/client"
	"github.com/micro/go-micro/metadata"
	sns "github.com/wufly/sns"
)

func main() {
	// New Service
	service := micro.NewService(
		micro.Name("com.weather.cron.srv.cron"),
		micro.Version("latest"),
	)

	// Initialise service
	service.Init()
	for i := 0; i < 10; i++ {
		call(i, service.Client())
	}

}

func call(i int, c client.Client) {
	// Create new request to service go.micro.srv.example, method Example.Call
	req := c.NewRequest("com.weather.srv.sns", "Send", &sns.Request{
		Phone:   "18457977915",
		Context: "aaaa",
	})

	// create context with metadata
	ctx := metadata.NewContext(context.Background(), map[string]string{
		"X-User-Id": "john",
		"X-From-Id": "script",
	})

	rsp := &sns.Response{}

	// Call service
	if err := c.Call(ctx, req, rsp); err != nil {
		fmt.Println("call err: ", err, rsp)
		return
	}

	fmt.Println("Call:", i, "rsp:", rsp.Msg)
}
